# -*- coding: utf-8 -*-
# @Time :    2022/6/10 14:24
# @Author :  mac
# @File :    simulator
# @Project : appium
# @Description

import yaml
from appium import webdriver


def desired():
    # 读取YAML配置文件
    with open('../Data/caps_simulator.yaml', 'r', encoding='utf-8') as file:
        data = yaml.full_load(file)  # yaml 5.1新用法

    # 初始化配置数据
    caps = dict()
    caps['platformName'] = data['platformName']
    caps['platformVersion'] = data['platformVersion']
    caps['deviceName'] = data['deviceName']
    caps['udid'] = data['udid']
    caps['bundleId'] = data['bundleId']
    caps['automationName'] = data['automationName']
    caps['xcodeSigningId'] = data['xcodeSigningId']

    # 自动安装APP
    # caps['app'] = data['app']

    # false,清除session信息；true不清除session信息
    caps['noReset'] = data['noReset']

    # 自动同意隐私授权
    caps['autoAcceptAlerts'] = data['autoAcceptAlerts']

    # 启动APP
    driver = webdriver.Remote('http://'+str(data['ip'])+':'+str(data['port'])+'/wd/hub', caps)

    driver.implicitly_wait(8)
    return driver

